package shiyan3;

import java.util.List;

public class SymmetricMatrixMain {
    public static void main(String[] args) {
        // Create a 5x5 symmetric matrix
        SymmetricMatrix M = new SymmetricMatrix(5);
        // Fill some values; setting either (i,j) or (j,i) is equivalent
        M.set(1, 1, 4.0);
        M.set(1, 3, 2.5);
        M.set(2, 5, -1.0);
        M.set(4, 2, 7.2); // same as set(2,4, 7.2)
        M.set(5, 5, 9.9);

        // Print matrix and info
        M.printMatrix();
        System.out.println();
        M.printInfo();
        System.out.println();

        // Access a specific element
        System.out.println("M[2,4] 的值 = " + M.get(2, 4));
        System.out.println("M[4,2] 的值 = " + M.get(4, 2));
        System.out.println();

        // Find all positions of a value
        double target = 2.5;
        List<int[]> positions = M.findAll(target);
        if (positions.isEmpty()) {
            System.out.println("矩阵中未找到值 " + target + "。");
        } else {
            System.out.println("值 " + target + " 的位置：");
            for (int[] rc : positions) {
                System.out.println("(" + rc[0] + ", " + rc[1] + ")");
            }
        }
        System.out.println();

        // Demonstrate matrix addition
        SymmetricMatrix N = new SymmetricMatrix(5);
        N.set(1, 3, 1.5);
        N.set(2, 5, 3.0);
        N.set(3, 3, 2.0);
        SymmetricMatrix S = M.add(N);

        System.out.println("M + N 的结果：");
        S.printMatrix();
    }
}
